package com.moji.java_moji.service;

import com.moji.java_moji.entity.user;
import com.moji.java_moji.mapper.userMapper;
import com.moji.java_moji.utils.JsonMapBuild;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import javax.annotation.Resource;
import java.util.HashMap;

@Service
public class UserSerice {
    @Resource
    private userMapper userMap;

    public HashMap<String,Object> login(HashMap<String,String> loginfo){
        String account = loginfo.get("account");
        String password = DigestUtils.md5DigestAsHex(loginfo.get("password").getBytes());
        user user = userMap.getUserByAccount(account);
        HashMap<String,Object> map;
        if(user == null){
            map = JsonMapBuild.getJsonMap("2","account error");
        }else if(password != user.getPassword()){
            map = JsonMapBuild.getJsonMap("3","account or password error");
        }else if(password == user.getPassword()){
            map = JsonMapBuild.getJsonMap("0","success",user);
        }else{
            map = JsonMapBuild.getJsonMap("4","unknown error");
        }
        return map;
    }

    public Integer test(){
        return userMap.test();
    }
}
